/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.localapp;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.suspend.b.b.h;
import com.qihoo.gamecenter.sdk.suspend.b.b.j;
import com.qihoo.gamecenter.sdk.suspend.remote.QRemoteService;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@SuppressLint({ "HandlerLeak" })
public class ApkInstallationReceiver extends BroadcastReceiver {
    private Context a;
    private j b;
    private Handler c = new Handler() {
        public void handleMessage(Message paramMessage) {
            switch (paramMessage.what) {
            case 1:
                ApkInstallationReceiver.this.a((String) paramMessage.obj);
                com.qihoo.gamecenter.sdk.suspend.b.b.a("ApkInstallationCondition", "installed:"
                        + ((String) paramMessage.obj));
                break;
            case 2:
                ApkInstallationReceiver.a((String) paramMessage.obj,
                        ApkInstallationReceiver.a(ApkInstallationReceiver.this));
                com.qihoo.gamecenter.sdk.suspend.b.b.a("ApkInstallationCondition", "removed:"
                        + ((String) paramMessage.obj));
                break;
            case 5:
                ApkInstallationReceiver.this.a((String) paramMessage.obj);
                com.qihoo.gamecenter.sdk.suspend.b.b.a("ApkInstallationCondition", "replaced:"
                        + ((String) paramMessage.obj));
            case 3:
            case 4:
            }
            super.handleMessage(paramMessage);
        }
    };

    public void a(String paramString) {
        if ((this.a == null) || (TextUtils.isEmpty(paramString)))
            return;
        a(paramString, this.a);
        b localb = c.a(this.a, paramString);
        if (localb == null)
            return;
        ArrayList localArrayList = new ArrayList();
        try {
            JSONObject localJSONObject = new JSONObject();
            localJSONObject.put("pkgname", localb.e());
            localJSONObject.put("vers", localb.d());
            localJSONObject.put("size", localb.c());
            localJSONObject.put("sdkkey", localb.a());
            localJSONObject.put("sdkid", localb.b());
            JSONArray localJSONArray = new JSONArray();
            localJSONArray.put(localJSONObject);
            h.a(localArrayList, "ks", localJSONArray.toString());
            if ("com.qihoo.gameunion".equals(paramString)) {
                com.qihoo.gamecenter.sdk.suspend.c.a.a(this.a, true);
                com.qihoo.gamecenter.sdk.suspend.c.a.b(this.a, localb.d());
                if (com.qihoo.gamecenter.sdk.suspend.remote.b.b().a())
                    com.qihoo.gamecenter.sdk.suspend.remote.b.b().g();
            }
        } catch (JSONException localJSONException) {
            localJSONException.printStackTrace();
        }
        String str = com.qihoo.gamecenter.sdk.suspend.b.d.a.m;
        try {
            str = com.qihoo.gamecenter.sdk.suspend.b.d.a.m + QRemoteService.a().b(paramString);
        } catch (RemoteException localRemoteException) {
            localRemoteException.printStackTrace();
        }
        this.b = new j(this.a, str, null, false);
        this.b.execute(new List[] { localArrayList });
    }

    public void onReceive(Context paramContext, Intent paramIntent) {
        if ((paramIntent == null) || (paramContext == null))
            return;
        this.a = paramContext;
        String str1 = paramIntent.getDataString();
        if (TextUtils.isEmpty(str1))
            return;
        String str2 = "";
        if (str1.length() > 1)
            str2 = str1.split(":")[1];
        else
            return;
        str2 = str1.split(":")[1];
        if (TextUtils.isEmpty(str2))
            return;
        Message localMessage;
        if ("android.intent.action.PACKAGE_ADDED".equals(paramIntent.getAction())) {
            localMessage = new Message();
            localMessage.what = 1;
            localMessage.obj = str2;
            this.c.sendMessage(localMessage);
        }
        else if ("android.intent.action.PACKAGE_REMOVED".equals(paramIntent.getAction())) {
            localMessage = new Message();
            localMessage.what = 2;
            localMessage.obj = str2;
            this.c.sendMessage(localMessage);
        }
        else {
            if (!("android.intent.action.PACKAGE_REPLACED".equals(paramIntent.getAction())))
                return;
            localMessage = new Message();
            localMessage.what = 5;
            localMessage.obj = str2;
            this.c.sendMessage(localMessage);
        }
    }

    public static void a(String paramString, Context paramContext) {
        String str = com.qihoo.gamecenter.sdk.suspend.c.a.a(paramContext);
        if ((!(TextUtils.isEmpty(str))) && (!(TextUtils.isEmpty(str)))
                && (str.indexOf("\"" + paramString + "\"") != -1)) {
            if (str.indexOf("\"" + paramString + "\",") != -1)
                str = str.replace("\"" + paramString + "\",", "");
            else
                str = str.replace("\"" + paramString + "\"", "");
            com.qihoo.gamecenter.sdk.suspend.remote.b.b().d(paramString);
            com.qihoo.gamecenter.sdk.suspend.c.a.a(paramContext, str);
        }
        if (!("com.qihoo.gameunion".equals(paramString)))
            return;
        com.qihoo.gamecenter.sdk.suspend.c.a.a(paramContext, false);
        com.qihoo.gamecenter.sdk.suspend.c.a.b(paramContext, "");
        if (!(com.qihoo.gamecenter.sdk.suspend.remote.b.b().a()))
            return;
        com.qihoo.gamecenter.sdk.suspend.remote.b.b().g();
    }
}